package cn.itcast.controller;

import cn.itcast.MemberService;
import cn.itcast.constant.MessageConstant;
import cn.itcast.constant.RedisMessageConstant;
import cn.itcast.pojo.Member;
import cn.itcast.pojo.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
  @Reference
  private MemberService memberService;
    @Autowired
  private   JedisPool jedisPool;
@RequestMapping("/check")
    public Result check(@RequestBody Map map){
   String   telephone= (String)  map.get("telephone");
   String   telephoneCode=(String)map.get("validateCode") ;
    String validateCode = jedisPool.getResource().get(telephone + RedisMessageConstant.SENDTYPE_LOGIN);
    if (validateCode==null||!validateCode.equals(telephoneCode)){
        return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);

    }else {
        boolean res  = memberService.checkMemberByTelephone(telephone);

       if (res){
return new Result(true,"");
    }}
    return new Result(false,"");
    }

}
